package com.example.tijianserver.service;

import com.example.tijianserver.mapper.CheckItemMapper;
import com.example.tijianserver.mapper.SetmealMapper;
import com.example.tijianserver.pojo.CheckItem;
import com.example.tijianserver.pojo.Hospital;
import com.example.tijianserver.pojo.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {

    @Autowired
    SetmealMapper setmealMapper;

    @Autowired
    CheckItemMapper checkItemMapper;

    @Override
    public List<Setmeal> listByType(Setmeal setmeal){

        List<Setmeal> setmealList=setmealMapper.selectByType(setmeal.getType());

        for (Setmeal sm:setmealList){
            Integer smId=sm.getSmId(); //获取套餐编号
            List<Integer> ciIdList = setmealMapper.selectBySmId(smId); //获取对应检查项编号
            //对检查项编号集合进行遍历，拿着每个编号去检查表中查询检查项所有信息
            List<CheckItem> checkItemList = new ArrayList<>();
            for (Integer ciId:ciIdList){
                CheckItem checkItem = checkItemMapper.selectByPrimaryKey(ciId);
                //每查询一个出来，就给到套餐对象
                checkItemList.add(checkItem);
            }
            sm.setCheckItemList(checkItemList);
        }
        return setmealList; //这个返回既包含套餐数据，又包含检查项数据
    }

    @Override
    public Setmeal getSetmealById(Setmeal setmeal){
        Setmeal setmeal1 = setmealMapper.selectByPrimaryKey(setmeal.getSmId());
        return setmeal1;
    }
}
